<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of SelectorBlock
 *
 * @author jnankin
 */
class SelectorBlock {

    private $selectors = array();
    private $styles = array();
    
    public function __construct($selectors, $styles){
        $this->addSelectors($selectors);
        $this->addStyles($styles);
    }

    public function addSelectors($selectorString){
        $selectors = explode(',', $selectorString);

        if (!is_array($selectors)) $selectors = array($selectors);

        foreach($selectors as $selector){
            $selector = trim(selector);
            if (!in_array($selector, $this->selectors))
                $this->selectors[] = $selector;
        }
    }

    public function addStyles($styleString){
         $styles = explode(';', $styleString);
         if (!is_array($styles)) $styles = array($styles);

         foreach($styles as $styleStr){
             $styleStr = trim($styleStr);
             $style = Style::create($styleStr);
             if (array_key_exists($style->getName(), $this->styles)){
                 $this->styles[$style->getName()]->combine($style);
             }
             else {
                 $this->styles[$style->getName()] = $style;
             }
         }
    }
}
?>
